/* Basic temperature system control in chapter 2 of tronixstuff.
   If light is red, "heater" is on because temp is low.
   If light is blue, "a/c" is on because temp is high.
   If light is green, temp is just right. */

// Initializations
int red = 3;
int green = 5;
int blue = 6;
int i, j;
float ctemp = 0.0;
float ftemp = 0.0;

void setup() {
   pinMode(red,OUTPUT);
   pinMode(green,OUTPUT);
   pinMode(blue,OUTPUT);
   Serial.begin(9600);
}

void loop() {
   ctemp = analogRead(5)*5000.0/1024/10; // temp in C
   ftemp = ctemp * 1.8 + 32.0; // temp in F

   // Compare temperature to decide what to do
   if (ftemp < 69.0) { // turn on heater
      analogWrite(red,255);
      delay(10);
      analogWrite(green,0);
      delay(10);
      analogWrite(blue,0);
      delay(10);
   }
   else if (ftemp > 72.0) { // turn on a/c
      analogWrite(red,0);
      delay(10);
      analogWrite(green,0);
      delay(10);
      analogWrite(blue,255);
      delay(10);
   }
   else { // in the right spot
      analogWrite(red,0);
      delay(10);
      analogWrite(green,255);
      delay(10);
      analogWrite(blue,0);
      delay(10);
   }
   
   Serial.print("Temp: ");
   Serial.println(ftemp);
   delay(1000);
}
